package com.seahorse.youliao.controller;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.seahorse.youliao.service.SysUserService;
import com.seahorse.youliao.service.entity.SysUserDTO;
import com.seahorse.youliao.utils.BeanUtil;
import com.seahorse.youliao.vo.request.SysUserQueryVO;
import com.seahorse.youliao.vo.response.SysUserPageInfoVO;
import com.seahorse.youliao.vo.response.SysUserResponseVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

/**
* describe: 用户信息表
* @author : songqiang
* @date: 2020-01-17 09:23:46.152
**/
@RestController
@Api("SysUserController")
@RequestMapping("sysUser")
@Validated
public class SysUserController {
	
    private static final Logger LOGGER = LoggerFactory.getLogger(SysUserController.class);
    
	@Autowired
    private SysUserService sysUserService;
    /**
     * 分页查询
     * @param sysUserQueryVO 分页查询参数
     * @return 分页参数
     */
    @ApiOperation(value = "分页查询")
    @PostMapping("getPageList")
    public SysUserPageInfoVO selectPageList(@RequestBody @Valid SysUserQueryVO sysUserQueryVO) {
        String info = String.format("The method name[selectPageList] params:%s", sysUserQueryVO.toString());
        LOGGER.info(info);
        SysUserDTO sysUser = BeanUtil.convert(sysUserQueryVO, SysUserDTO.class);

        Page<SysUserResponseVO> page = PageHelper.startPage(sysUserQueryVO.getPageNum(), sysUserQueryVO.getPageSize());
        List<SysUserDTO> sysUserList = sysUserService.getList(sysUser);
        SysUserPageInfoVO sysUserPageInfo = new SysUserPageInfoVO();
        BeanUtils.copyProperties(page.toPageInfo(), sysUserPageInfo);
        List<SysUserResponseVO> voList = BeanUtil.convert(sysUserList, SysUserResponseVO.class);
        sysUserPageInfo.setList(voList);

        return sysUserPageInfo;
    }


}
